

/**
 * 
 * @param callback - 
 * @returns 
 */
export function useSwipe(callback: () => void) {
  const startTouch = { x: 0, y: 0 };
  const endTouch = { x: 0, y: 0 };

  
  const handleTouchStart = (event: TouchEvent): void => {
    startTouch.x = event.touches[0].clientX;
    startTouch.y = event.touches[0].clientY;
  };

  
  const handleTouchMove = (event: TouchEvent): void => {
    
    const diffX = endTouch.x - startTouch.x;
    const diffY = endTouch.y - startTouch.y;

    if (Math.abs(diffX) > 10 || Math.abs(diffY) > 10) {
      event.preventDefault();  
    }

    endTouch.x = event.touches[0].clientX;
    endTouch.y = event.touches[0].clientY;
  };

  const handleTouchEnd = (): void => {
    const diffX = endTouch.x - startTouch.x;
    const diffY = endTouch.y - startTouch.y;
  
    console.log(`diffX: ${diffX}, diffY: ${diffY}`);  
  
    if (Math.abs(diffY) < Math.abs(diffX) && diffX > 30) {  
      callback(); 
    }
  };

  return { handleTouchStart, handleTouchMove, handleTouchEnd };
}

